#include <iostream>
using namespace std;

/*
	受到cout输出的原理启发，我想直接打印(输出)结构体，自定义的类对象(猫)
*/

class Cat
{
public:
	Cat(string _name,float _weight,int _age)
	{
		name=_name;
		weight=_weight;
		age=_age;
	}
	//friend void operator<<(ostream &out,Cat &other); //缺陷：无法连续打印
	friend ostream &operator<<(ostream &out,Cat &other); //可以连续打印
private:
	int age;
	string name;
	float weight;
};

//void operator<<(ostream &out,Cat &other)   //缺陷：无法连续打印
ostream &operator<<(ostream &out,Cat &other) //可以连续打印
{
	cout<<"友元函数被调用"<<endl;
	out<<other.name<<endl;
	out<<other.weight<<endl;
	out<<other.age<<endl;
	return out;
}

int main()
{
	Cat c1("旺财",55.8,5);
	Cat c2("来福",56.8,6);
	/*
		人类的思维习惯
		   cout<<c1;
		   cout<<c1<<c2;
		函数调用
		   cout.operator<<(c1)  //成员函数，不正确，ostream这个类里面根本就没有这个版本
		   operator<<(cout,c1)  //友元函数，正确

	*/
	//人类的思维习惯
	//cout<<c1;
	cout<<c1<<c2;
	//函数调用
	//operator<<(cout,c2);
	//浓缩，不好理解
	operator<<(operator<<(cout,c1),c2);
}